#include <linux/init.h>
#include <linux/module.h>
#include <asm/vmx.h>
#include <linux/kernel.h>
#include <asm/cpufeatures.h>
#include <asm/virtext.h>

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("A driver for vt_learn");

static int __init hello_vt(void){
    printk(KERN_INFO "Hello, vt_learn!\n");
    printk(KERN_INFO "I include vmx.h\n");
    {
        uint eax, ebx, ecx, edx;
        eax = 1;
        __asm__ volatile(
                "cpuid;"
                : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
                : "a"(eax)
                );
        printk(KERN_INFO "ecx: 0x%x\n", ecx);
        printk(KERN_INFO "ecx[bit 5] = %x\n\n", ecx >> 5 & 1);
    }

    {
        unsigned long ecx = cpuid_ecx(1);
        printk(KERN_INFO "cpuid_ecx(1), ecx: 0x%lx\n", ecx);
        printk(KERN_INFO "ecx[bit 5] = %lx\n\n", ecx >> 5 & 1);
    }

    {
        printk(KERN_INFO "cpu_has_vmx(): %d\n", cpu_has_vmx());
    }

    {
        printk(KERN_INFO "boot_cpu_has(X86_FEATURE_VMX): %d\n", boot_cpu_has(X86_FEATURE_VMX));
    }

    return 0;
}

static void __exit exit_vt(void){
    printk(KERN_INFO "-----Goodbye, vt_learn!----\n\n\n\n\n\n\n\n");
}

module_init(hello_vt);
module_exit(exit_vt);